(*$U-*)
PROGRAM PASCALSYSTEM;

(************************************************)
(*                                              *)
(*    UCSD PASCAL OPERATING SYSTEM              *)
(*                                              *)
(*    RELEASE LEVEL:  I.3			*)
(*						*)
(*    WRITTEN BY ROGER T. SUMNER                *)
(*    WINTER 1977                               *)
(*                                              *)
(*    INSTITUTE FOR INFORMATION SYSTEMS         *)
(*    UC SAN DIEGO, LA JOLLA, CA                *)
(*                                              *)
(*    KENNETH L. BOWLES, DIRECTOR               *)
(*                                              *)
(*    THIS SOFTWARE IS THE PROPERTY OF THE      *)
(*  REGENTS OF THE UNIVERSITY OF CALIFORNIA.    *)
(*                                              *)
(************************************************)

CONST
     MAXUNIT = 8;	(*MAXIMUM PHYSICAL UNIT # FOR UREAD*)
     MAXDIR = 77;	(*MAX NUMBER OF ENTRIES IN A DIRECTORY*)
     VIDLENG = 7;	(*NUMBER OF CHARS IN A VOLUME ID*)
     TIDLENG = 15;	(*NUMBER OF CHARS IN TITLE ID*)
     MAXSEG = 15;	(*MAX CODE SEGMENT NUMBER*)
     FBLKSIZE = 512;	(*STANDARD DISK BLOCK LENGTH*)
     DIRBLK = 2;	(*DISK ADDR OF DIRECTORY*)
     AGELIMIT = 600;	(*MAX AGE FOR GDIRP...IN TICKS*)
     EOL = 13;		(*END-OF-LINE...ASCII CR*)

TYPE

     IORSLTWD = INTEGER;

					(*ARCHIVAL INFO...THE DATE*)

     DATEREC = INTEGER;

					(*VOLUME TABLES*)
     UNITNUM = 0..MAXUNIT;
     VID = STRING[VIDLENG];

					(*DISK DIRECTORIES*)
     DIRRANGE = 0..MAXDIR;
     TID = STRING[TIDLENG];

     FILEKIND = INTEGER;

     DIRENTRY = INTEGER;
     DIRP = ^DIRECTORY;

     DIRECTORY = ARRAY [DIRRANGE] OF DIRENTRY;

					(*FILE INFORMATION*)

     CLOSETYPE = INTEGER;
     WINDOWP = ^WINDOW;
     WINDOW = PACKED ARRAY [0..0] OF CHAR;
     FIBP = ^FIB;

     FIB = INTEGER;

					(*USER WORKFILE STUFF*)

					(*CODE SEGMENT LAYOUTS*)

     SEGRANGE = 0..MAXSEG;
     SEGDESC = INTEGER;

					(*DEBUGGER STUFF*)

     BYTERANGE = 0..255;
     MSCWP = ^ MSCW;		(*MARK STACK RECORD POINTER*)
     MSCW = INTEGER;

					(*SYSTEM COMMUNICATION AREA*)
					(*SEE INTERPRETERS...NOTE  *)
					(*THAT WE ASSUME BACKWARD  *)
					(*FIELD ALLOCATION IS DONE *)
     SYSCOMREC = RECORD
		   IORSLT: IORSLTWD;	(*RESULT OF LAST IO CALL*)
		   XEQERR: INTEGER;	(*REASON FOR EXECERROR CALL*)
		   SYSUNIT: UNITNUM;	(*PHYSICAL UNIT OF BOOTLOAD*)
		   BUGSTATE: INTEGER;(*DEBUGGER INFO*)
		   GDIRP: DIRP;		(*GLOBAL DIR POINTER,SEE VOLSEARCH*)
		   LASTMP,STKBASE,BOMBP: MSCWP;
		   MEMTOP,SEG,JTAB: INTEGER;
		   BOMBIPC: INTEGER;	(*WHERE XEQERR BLOWUP WAS*)
		   EXPANSION: ARRAY [0..14] OF INTEGER;
		   HIGHTIME,LOWTIME: INTEGER;
		   MISCINFO: PACKED RECORD
			       NOBREAK,STUPID,SLOWTERM,
			       HASXYCRT,HASLCCRT,HAS8510A,HASCLOCK: BOOLEAN
			     END;
		   CRTTYPE: INTEGER;
		   CRTCTRL: PACKED RECORD
			      RLF,NDFS,ERASEEOL,ERASEEOS,HOME,ESCAPE: CHAR;
			      BACKSPACE: CHAR;
			      FILLCOUNT: 0..255;
			      EXPANSION: PACKED ARRAY [0..3] OF CHAR
			    END;
		   CRTINFO: PACKED RECORD
			      WIDTH,HEIGHT: INTEGER;
			      RIGHT,LEFT,DOWN,UP: CHAR;
			      BADCH,CHARDEL,STOP,BREAK,FLUSH,EOF: CHAR;
			      ALTMODE,LINEDEL: CHAR;
			      EXPANSION: PACKED ARRAY [0..5] OF CHAR
			    END;
		   SEGTABLE: ARRAY [SEGRANGE] OF
			       RECORD
				 CODEUNIT: UNITNUM;
				 CODEDESC: SEGDESC
			       END
		 END (*SYSCOM*);

VAR
    SYSCOM: ^SYSCOMREC;			(*MAGIC PARAM...SET UP IN BOOT*)
    GFILES: ARRAY [0..5] OF FIBP;	(*GLOBAL FILES, 0=INPUT, 1=OUTPUT*)
    EMPTYHEAP: ^INTEGER;		(*HEAP MARK FOR MEM MANAGING*)
    INPUTFIB,OUTPUTFIB,SYSTERM: FIBP;	(*ACTUAL FILES...GFILES ARE COPIES*)
    SYVID,DKVID: VID;			(*SYSUNIT VOLID & DEFAULT VOLID*)
    THEDATE: DATEREC;			(*TODAY...SET IN FILER OR SIGN ON*)
    DEBUGINFO: ^INTEGER;		(*DEBUGGERS GLOBAL INFO WHILE RUNIN*)
    PL: STRING;				(*PROMPTLINE STRING...SEE PROMPT*)
(*-------------------------------------------------------------------------*)
(* SYSTEM PROCEDURE FORWARD DECLARATIONS *)
(* THESE ARE ADDRESSED BY OBJECT CODE... *)
(*  DO NOT MOVE WITHOUT CAREFUL THOUGHT  *)

PROCEDURE EXECERROR;
  FORWARD;
PROCEDURE FINIT(VAR F: FIB; WINDOW: WINDOWP; RECWORDS: INTEGER);
  FORWARD;
PROCEDURE FRESET(VAR F: FIB);
  FORWARD;
PROCEDURE FOPEN(VAR F: FIB; VAR FTITLE: STRING;
		FOPENOLD: BOOLEAN; JUNK: FIBP);
  FORWARD;
PROCEDURE FCLOSE(VAR F: FIB; FTYPE: CLOSETYPE);
  FORWARD;
PROCEDURE FGET(VAR F: FIB);
  FORWARD;
PROCEDURE FPUT(VAR F: FIB);
  FORWARD;
PROCEDURE FSEEK(VAR F: FIB);
  FORWARD;
FUNCTION FEOF(VAR F: FIB): BOOLEAN;
  FORWARD;
FUNCTION FEOLN(VAR F: FIB): BOOLEAN;
  FORWARD;
PROCEDURE FREADINT(VAR F: FIB; VAR I: INTEGER);
  FORWARD;
PROCEDURE FWRITEINT(VAR F: FIB; I,RLENG: INTEGER);
  FORWARD;
PROCEDURE FREADREAL(VAR F: FIB; VAR X: REAL);
  FORWARD;
PROCEDURE FWRITEREAL(VAR F: FIB; X: REAL; W,D: INTEGER);
  FORWARD;
PROCEDURE FREADCHAR(VAR F: FIB; VAR CH: CHAR);
  FORWARD;
PROCEDURE FWRITECHAR(VAR F: FIB; CH: CHAR; RLENG: INTEGER);
  FORWARD;
PROCEDURE FREADSTRING(VAR F: FIB; VAR S: STRING; SLENG: INTEGER);
  FORWARD;
PROCEDURE FWRITESTRING(VAR F: FIB; VAR S: STRING; RLENG: INTEGER);
  FORWARD;
PROCEDURE FWRITEBYTES(VAR F: FIB; VAR A: WINDOW; RLENG,ALENG: INTEGER);
  FORWARD;
PROCEDURE FREADLN(VAR F: FIB);
  FORWARD;
PROCEDURE FWRITELN(VAR F: FIB);
  FORWARD;
PROCEDURE SCONCAT(VAR DEST,SRC: STRING; DESTLENG: INTEGER);
  FORWARD;
PROCEDURE SINSERT(VAR SRC,DEST: STRING; DESTLENG,INSINX: INTEGER);
  FORWARD;
PROCEDURE SCOPY(VAR SRC,DEST: STRING; SRCINX,COPYLENG: INTEGER);
  FORWARD;
PROCEDURE SDELETE(VAR DEST: STRING; DELINX,DELLENG: INTEGER);
  FORWARD;
FUNCTION SPOS(VAR TARGET,SRC: STRING): INTEGER;
  FORWARD;
FUNCTION FBLOCKIO(VAR F: FIB; VAR A: WINDOW;
		  NBLOCKS,RBLOCK: INTEGER; DOREAD: BOOLEAN): INTEGER;
  FORWARD;

(* NON FIXED FORWARD DECLARATIONS *)

FUNCTION VOLSEARCH(VAR FVID: VID; LOOKHARD: BOOLEAN;
		   VAR FDIR: DIRP): UNITNUM;
  FORWARD;
PROCEDURE WRITEDIR(FUNIT: UNITNUM; FDIR: DIRP);
  FORWARD;
FUNCTION DIRSEARCH(VAR FTID: TID; FINDPERM: BOOLEAN; FDIR: DIRP): DIRRANGE;
  FORWARD;
FUNCTION SCANTITLE(FTITLE: STRING; VAR FVID: VID; VAR FTID: TID;
		   VAR FSEGS: INTEGER; VAR FKIND: FILEKIND): BOOLEAN;
  FORWARD;
PROCEDURE DELENTRY(FINX: DIRRANGE; FDIR: DIRP);
  FORWARD;
PROCEDURE INSENTRY(VAR FENTRY: DIRENTRY; FINX: DIRRANGE; FDIR: DIRP);
  FORWARD;
PROCEDURE CLEARSCREEN;
  FORWARD;
PROCEDURE PROMPT;
  FORWARD;
FUNCTION SPACEWAIT: BOOLEAN;
  FORWARD;
FUNCTION GETCHAR(FLUSH: BOOLEAN): CHAR;
  FORWARD;
PROCEDURE EXECUTE(RUNWORKFILE: BOOLEAN);
  FORWARD;
PROCEDURE COMMAND;
  FORWARD;

(* Interactive Pascal Debugger*)
(* Version I.3  Released 7/21/77 *)

(* Written Summer 1977 *)
(* Author  Joel McCormack *)
(* Assistant authors Dave Wollner, Chip Chapin, Lucia Bennett *)

SEGMENT PROCEDURE USERPROGRAM(VAR INPUT, OUTPUT: TEXT);
BEGIN END; (* USERPROGRAM *)

SEGMENT PROCEDURE COMPILER;
  SEGMENT PROCEDURE COMPINIT;
  BEGIN END; (* COMPINIT *)
BEGIN END; (* COMPILER *)

SEGMENT PROCEDURE EDITOR;
BEGIN END; (* EDITOR *)

SEGMENT PROCEDURE FILEHANDLER;
BEGIN END; (* FILEHANDLER *)




SEGMENT PROCEDURE DEBUGGER;

CONST
  (* Special Characters *)
  ORDALT = 27;
  ORDCR = 13;
  ORD0 = 48;

  (* Positioning of info on screen *)
  PROMPTLINE = 0;
  INFOLINE = 3;
  HEADINGLINE = 7;
  FIRSTDATALINE = 8;
  LINKCOLUMN = 54;

  (* Information about the hardware and implementation *)
  DELTAMSCW = 12;
  DATAOFFSET = 1; (* The first data offset *)
  WORDSZ = 2;
  BYTESPERWORD = 2;
  LOBYTE = 1;
  HIBYTE = 2;
  HEXPERWORD = 4;
  MAXBREAKPNTS = 9;
  JTABPROCANDLL = 0; (* The offsets by words in the JUMPTABLE.  Indexed off of
			@JTAB *)
  JTABENTRIC = -1;
  JTABEXITIC = -2;
  JTABPARMSZ = -3;
  JTABDATASZ = -4;

  (* BUGSTATES *)
  ASLEEP = 0;   WAKINGUP = 1;   CRAWLING = 2;
  WALKING = 3;  RUNNING = 4;    EXAMINING = 5;

TYPE
     DEBUGLINE = (EMPTYLINE,DATALINE,STACKLINE,POINTERLINE);
     BUGINFOREC = RECORD
		      BUFFEREMPTY: BOOLEAN;
		      DATAPLACE: INTEGER;
		      SCREENINFO: ARRAY [8..22] OF
				    RECORD
					CASE LINETYPE: DEBUGLINE OF
					  DATALINE,STACKLINE:
					    (SEG: SEGRANGE;
					     PROC: BYTERANGE;
					     DISP: INTEGER);
					  POINTERLINE:
					    (HEAPPOINTER: INTEGER)
				    END
		    END (*BUGINFOREC*) ;
  OCTRANGE = 0..7;
  HEXRANGE = 0..15;
  MEMTYPE = RECORD CASE INTEGER OF  (* Used to get at memory in various
				     and convenient ways *)
	      0: (INTVAL: INTEGER);
	      1: (HEXVAL: PACKED ARRAY[1..HEXPERWORD] OF HEXRANGE);
	      2: (BYTEVAL: PACKED ARRAY[1..BYTESPERWORD] OF BYTERANGE);
	      3: (CHARVAL: PACKED ARRAY[1..BYTESPERWORD] OF CHAR);
	      4: (OCTVAL: PACKED RECORD
			    FD0, FD1, FD2, FD3, FD4: OCTRANGE;
			    FIRSTDIGIT: 0..1
			  END);
	      5: (BYTEOCTVAL: PACKED RECORD
				LD1, LD2: OCTRANGE;
				LD0: 0..3;
				HD1, HD2: OCTRANGE;
				HD0: 0..3
			      END);
	      6: (PTVAL: ^MEMTYPE)
	    END;(* RECORD MEMTYPE *)
  MEMARRAY = ARRAY [0..0] OF MEMTYPE;

  DMSCWP = ^DMSCW;
  DMSCW = RECORD  (* MSCW in convenient format *)
	    MSSTAT: DMSCWP;
	    MSDYN: DMSCWP;
	    MSJTAB: ^MEMARRAY;
	    MSSEG: ^MEMTYPE;
	    MSIPC: INTEGER;
	    MSSP: ^MEMARRAY;
	    MSDATA:  ARRAY [DATAOFFSET..DATAOFFSET] OF MEMTYPE
	  END; (* Debug Mark Stack Control Word *)

  DIRECTYPE = (UP,DOWN);
  LINKTYPE = (STATIC,DYNAMIC);


VAR
  LASTDATALINE, COMLINE: INTEGER;

  BUGDEBUGINFO: ^BUGINFOREC;
  JEXERRP: DMSCWP;  (*Pointer to EXECERROR *)
  PPROCINFO, PLINKINFO: DMSCWP; (* Pointers to current proc *)

  DATOFF, STOFF,  (* Default offsets for stack and data *)
  LNGTH,  (* Default length to use *)
  SEGNUM, PROCNUM,  (* Info about current proc *)
  LINKLEVEL: INTEGER;  (* Number of DYNAMIC links above bombed proc *)
  LINKDEFAULT: LINKTYPE;
  DIRECTION: DIRECTYPE;

  DELAYCNT,  (* Used to wait while in WALKING mode *)

  DIGITSET: SET OF '0'..'9';
  DOWNCHARS: STRING[31];
  ACROSSCHARS: STRING[79];
